// pages/searchResult/searchResult.js
const httpRequest = require('../../utils/http_utils.js')
const dateutil = require('../../utils/date_util.js')
const common = require('../../utils/common.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: '', //input值
    pageSize: 30, //每页显示条数
    counter: 1, //计数器
    pageStart: 0, //开始数据条数
    dataList: [], //数据集合
    title: '搜索房间',
  },

  inputSearch: function(e) {
    e.detail.value
  },

  initdata: function() {
    var that = this;
    var CoditionArray = new Array();
    var param = {
      searchStr: that.data.info,
      rolename: '*',
      pagesize: that.data.pageSize,
      currentpage: that.data.counter,
      where: JSON.stringify(CoditionArray),
      orderby: "order by WorkTime desc",
      type: 2
    }
    console.log(JSON.stringify(param)+"给接口的数据")
    httpRequest.GetValidateRequest(httpRequest.apiInfo.ProjectGetSearchMobileApi, param, function(data) {
      console.log(JSON.stringify(data)+"接口数据")
      var pageDataInfo = data.pageData;
      if (pageDataInfo.length > 0) {
        for (var i = 0; i < pageDataInfo.length; i++) {
          var FailureTypeName = 'dataList[' + i + '].FailureTypeName';
          var WorkOrderId = 'dataList[' + i + '].WorkOrderId';
          var WorkTime = 'dataList[' + i + '].WorkTime';
          var WorkType = 'dataList[' + i + '].WorkType';
          that.setData({
            [FailureTypeName]: pageDataInfo[i].FailureTypeName,
            [WorkOrderId]: pageDataInfo[i].WorkOrderId,
            [WorkTime]: dateutil.dateFormat2(pageDataInfo[i].WorkTime),
            [WorkType]: common.getDicText('工单类型', pageDataInfo[i].WorkType),
          })
        }
      }
    }, function(err) {})
    console.log(JSON.stringify(that.data.dataList)+"数据集合")
  },

  fanhui: function() {
    wx.redirectTo({
      url: '../search/search',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      info: options.info
    })
    this.initdata();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})